#include <iostream>
#include <memory>
#include <string>
#include <vector>

using namespace std;

/*
\ brief:  之前的状态
\ author: 清晨与猫鱼
*/
class Memento {
public:
    explicit Memento(string state)
        : state_(move(state)) {            
    }

    string& getState() {
        return state_;
    }
private:
    string state_;
};


/*
\ brief:   发起人
\ author: 清晨与猫鱼
*/
class Originator {
public:

    void setState(string state) {
        state_ = move(state);
    }

    string& getState() {
        return state_;
    }

/*
\ brief:  保存之前的状态
\ author: 清晨与猫鱼
*/
    Memento saveStateToMemento() {
        return Memento(state_);
    }

/*
\ brief:  获取之前的状态
\ author: 清晨与猫鱼
*/
    void getStateFromMemento(Memento& memento) {
        state_ = memento.getState();
    }
private:
    string state_;
};


/*
\ brief:  临时代理
\ author: 清晨与猫鱼
*/
class CareTaker {
public:

/*
\ brief:   添加一个状态
\ author: 清晨与猫鱼
*/
    void add(const Memento& state) {
        mementoList_.push_back(state);
    }

/*
\ brief:  根据索引，返回指定的状态
\ author: 清晨与猫鱼
*/
    Memento& get(int index) {
        return mementoList_[index];
    }
private:
    vector<Memento> mementoList_;       // 状态表
};